package com.hotel.ordersystem.controller;

import com.hotel.utils.UploadImgUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
public class QiniuController {

    /**
     * 调用七牛云进行图片上传
     * @param myfile
     * @return
     */
    @PostMapping("/testUpdate")
    public Map upload(MultipartFile myfile) { // 文件接收对象
        Map map = new HashMap<>();
        try {
            String imgUrl = UploadImgUtil.upload(myfile.getBytes(),myfile.getOriginalFilename());
            map.put("imgUrl", imgUrl);
        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);
        }
        return map;
    }
}